<template>
  <div id="addForm" class="addalarmrecord">
    <slot id="formTitle">
      <h3 style="text-align: center">Edit Alarm</h3>
    </slot>
    <el-form ref="form" :model="form" label-width="80px" @submit.native.prevent>
      <el-form-item label="Name" style="width: 80%">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="Status">
        <el-select v-model="form.status" placeholder="Status" clearable>
          <el-option label="Open" value="Open"></el-option>
          <el-option label="Pending" value="Pending"></el-option>
          <el-option label="Closed" value="Closed"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="CreateTime">
        <el-col :span="11">
          <el-date-picker
            type="datetime"
            placeholder="Choose Time"
            v-model="form.gentime"
            style="width: 100%"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="Owner" style="width: 300px">
        <el-input v-model="form.handleby"></el-input>
      </el-form-item>
      <el-form-item label="From">
        <el-radio-group v-model="form.resource">
          <el-radio label="DV"></el-radio>
          <el-radio label="I2000"></el-radio>
          <el-radio label="Others"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="Progress" style="width: 90%">
        <el-input type="textarea" v-model="form.progress"></el-input>
      </el-form-item>
      <el-form-item>
        <slot id="submit"
          ><el-button @click="onSubmit">Confirm</el-button>
        </slot>
        <el-button @click="doClose">Cancel</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { updateAlarm } from "@/api/alarm.js";

export default {
  name: "editForm",
  props: {
    formVisible: Boolean,
    formData: {},
  },
  components: {},
  data() {
    return {
      visible: this.formVisible,
      form: this.formData,
    };
  },
  watch: {
    visible(val) {
      this.formVisible = val;
    },
  },
  computed: {},
  methods: {
    onSubmit() {
      updateAlarm(this.form).then((res) => {
        message("update success");
        this.$store.state.alarmRecordListSave = this.$store.state.alarmRecordList.slice(
          0
        );
      });
      this.$emit("formVisibleEvent", false);
    },
    doClose() {
      this.$emit("formVisibleEvent", false);
    },
  },
  created() {},
};
</script> 

<style scoped>
.addalarmrecord {
  margin: 10px;
  border: red 1px solid;
  width: 800px;
  background-color: #f1f5f5;
  position: absolute;
  top: 135px;
  left: 288px;
}
</style>